[PATCH] QtQml: Do not clear objects' propertyCaches on last GC run
authorUlf Hermann <ulf.hermann@qt.io>
Tue, 13 Jan 2026 10:53:27 +0000 (11:53 +0100)
committerPatrick Franz <deltaone@debian.org>
Thu, 19 Mar 2026 19:43:56 +0000 (20:43 +0100)
commitf6edbc9594a4ea3c1ed11d5b66ac2ae0ced169de
tree9eaf3340c8f065ad88e92d6343612c48bee76be2
parent8255bb30cb1e469a6e10d0eb864092dfda2ca7af
[PATCH] QtQml: Do not clear objects' propertyCaches on last GC run

The property caches are not specific to the engine. The same object may
be exposed to other engines and still require its property cache. When
the clearing of the property caches on engine destruction was
introduced, the property caches were still engine-specific and we had no
choice but to clear them. Otherwise any further access would lead to a
dereference of a dangling pointer.

Furthermore, when clearing the JS wrapper for a QObject, check if it's
actually the wrapper being deleted. We don't want to clear some other
engine's wrapper.

Amends commit 749a7212e903d8e8c6f256edb1836b9449cc7fe1.
Amends commit c6b2dd879d02b21b18f80faab541f8f04286685a.

Fixes: QTBUG-142514
Change-Id: I40bb1aeca65225d56cb1d2ff498f5f1722216a70
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit dc2358e98b8ddab532866a403ffc09d1162ad0f9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit abd054a491b5f443193033d451dc17e09841277a)

Gbp-Pq: Name upstream_qtqml_crash_fix.diff
src/qml/jsruntime/qv4qobjectwrapper.cpp
tests/auto/qml/qjsengine/tst_qjsengine.cpp
tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
tests/auto/qml/qmlcppcodegen/data/multiEnginePropertyCache.qml [new file with mode: 0644]
tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp